/**
 * 功能:虚假公告·魔方双倍奇迹时刻

 */

var setupTask;

//设置多久开启一次(小时:为单位)
var starttime = 6;

//设置每次活动结束的时间(分钟:为单位)
var overtime = 40;

//设置每次副本开启的分钟段(分钟:为单位)
var startminute = 15;

function init() {
	scheduleNew();
}

function scheduleNew() {
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时 24小时制
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	cal.set(java.util.Calendar.HOUR, 0); //设定的小时 12小时制
	cal.set(java.util.Calendar.MINUTE, startminute); //设定的分钟
	cal.set(java.util.Calendar.SECOND, 0); //设定的秒钟
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 * 60 * 60 * starttime; //设置多久开启
	}
	setupTask = em.scheduleAtTimestamp("startEvent", nextTime);
}

function startEvent() {
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时  24小时制
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	cal.set(java.util.Calendar.HOUR, 0); //设定的小时 12小时制
	cal.set(java.util.Calendar.MINUTE, startminute); //设定的分钟
	cal.set(java.util.Calendar.SECOND, 0); //设定的秒钟
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 * 60 * overtime; //设置多久结束
	}
	setupTask = em.scheduleAtTimestamp("finishEvent", nextTime);
	em.broadcastServerMsg(5120129, "双倍奇迹:当前服务器开启了洗魔方双倍几率！" + overtime + "分钟后将会恢复到原来的几率请抓紧时间洗魔方哟！", true);
	em.broadcastServerMsg("双倍奇迹:当前服务器开启了洗魔方双倍几率！" + overtime + "分钟后将会恢复到原来的几率请抓紧时间洗魔方哟！");
}

function finishEvent() {
	em.broadcastServerMsg("双倍奇迹时刻（魔方）:服务器当前关闭了洗魔方双倍几率，请等待下一次开启..");
	scheduleNew();
}

function cancelSchedule() {
	if (setupTask != null) {
		setupTask.cancel(true);
	}

}
